/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.spreedairy.portal.service.impl;

import com.liferay.portal.kernel.exception.SystemException;
import com.spreedairy.portal.NoSuchRecommendationException;
import com.spreedairy.portal.model.Recommendation;
import com.spreedairy.portal.service.base.RecommendationLocalServiceBaseImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * The implementation of the recommendation local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link com.spreedairy.portal.service.RecommendationLocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author SpreeDairy
 * @see com.spreedairy.portal.service.base.RecommendationLocalServiceBaseImpl
 * @see com.spreedairy.portal.service.RecommendationLocalServiceUtil
 */
public class RecommendationLocalServiceImpl
	extends RecommendationLocalServiceBaseImpl {
	
	public Recommendation findByUserId (long itemId, long userId, long groupId, long companyId) {
		Recommendation recommendation = null;
		try {
			recommendation = recommendationPersistence.findByUserId(itemId, userId, groupId, companyId);
		} catch (NoSuchRecommendationException e) {
			e.printStackTrace();
		} catch (SystemException e) {
			e.printStackTrace();
		}
		return recommendation;
	}
	
	public int getRecommendationCount(long itemId, long groupId, long companyId){
		List<Recommendation> recommendationList = new ArrayList<Recommendation>();
		try {
			recommendationList = recommendationPersistence.findByItemId(itemId, groupId, companyId);
		} catch (SystemException e) {
			e.printStackTrace();
		}
		return recommendationList.size();
	}
	
	public List<Long> getTopRecommendationIds(long companyId, long groupId){
		return recommendationFinder.getTopRecommendationIds(companyId, groupId);
	}
}